﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
using System.Data;

public partial class 数据库升级_UpdateDataBase : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DataSource = IsUpdateBase(false);
            GridView1.DataBind();
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        GridView1.DataSource = IsUpdateBase(true);
        GridView1.DataBind();
       
    }

    public DataTable IsUpdateBase(bool flag)
    {
        Assembly assemly = Assembly.LoadFrom(Server.MapPath("~/Bin/RoadTeam.DataBaseUpdate.dll"));
        Type[] AllClass = assemly.GetTypes().OrderBy(th => th.Name).ToArray();
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("Message", typeof(String)));
        foreach (Type T in AllClass)
        {
            if (T.Name.ToLower().Contains(("SqlHelper").ToLower())) continue;

            object obj = Activator.CreateInstance(T);
            MethodInfo[] Mi = T.GetMethods().OrderBy(th => th.Name).Where(th => th.Name.ToLower().Contains(("ExecuteSQL").ToLower())).ToArray();
            foreach (MethodInfo mi in Mi)
            {
                List<string> li = mi.Invoke(obj, new object[] { flag }) as List<string>;
                String TempVersion = mi.Name.Replace("ExecuteSQL", "");
                CreateTable(dt, li, TempVersion);
            }
        }
        return dt;
    }


    private void CreateTable(DataTable dt, List<string> li, string TempVersion)
    {
        DataRow dr;
        foreach (String Str in li)
        {
            dr = dt.NewRow();
            dr["Message"] = TempVersion + Str;
            dt.Rows.Add(dr);
        }
    }
}